//-----------------------------------------------------------------------------
// Name: BulletManager.cpp
// Auth: Paul Godfrey
// Desc: Keeps a list of Bullets
//-----------------------------------------------------------------------------


#include "GunManager.h"

#include <iostream>
#include <windows.h>
using namespace std;


cGunManager gGunManager;


//-----------------------------------------------------------------------------
// Functions:
//-----------------------------------------------------------------------------
cGunManager* GetGunManager()
{
	return &gGunManager;
}

cGunManager::cGunManager()
{

}

cGunManager::~cGunManager()
{
}

//Adds one bullet to the manager - queue position is irrelevent so it always adds to the front.
void cGunManager::addGun(int size, bool active, enum eGunType type )
{
	cGun* newGun = new cGun(size, active, type);

	liGuns.push_back(*newGun);

}


//Sets positions of guns
void cGunManager::SetPositions(float x, float y, float z, float ya, float p)
{
	mXPosition=x;
	mYPosition=y;
	mZPosition=z;
	mYaw = ya;
	mPitch = p;
}

//Draws a gun in the bottom middle of the screen
void cGunManager::Draw()
{
	itGun = liGuns.begin();
	while (itGun!=liGuns.end())
	{
		if(itGun->GetActive())
		{		
			//TODO Fix mem leak!
			itGun->Draw(mXPosition, mYPosition, mZPosition, mYaw, mPitch);
		}
		itGun++;

	}
}

//Set a gun active if Type is matched
void cGunManager::SetActive(enum eGunType t)
{
	itGun = liGuns.begin();
	while (itGun!=liGuns.end())
	{
		//itGun->Update(elapsedTimeS);
		if(t == itGun->GetType())
		{		
			itGun->SetActive(true);
		}
		else
		{
			itGun->SetActive(false);
		}
		itGun++;

	}
}

//Get the active gun
eGunType cGunManager::GetActive()
{
	itGun = liGuns.begin();
	while (itGun!=liGuns.end())
	{
		//itGun->Update(elapsedTimeS);
		if(itGun->GetActive())
		{		
			return itGun->GetType();
		}
		itGun++;

	}
	return Rifle;
}

//Get the clipsize for the active gun
int cGunManager::GetBullets()
{
	itGun = liGuns.begin();
	while (itGun!=liGuns.end())
	{
		//itGun->Update(elapsedTimeS);
		if(itGun->GetActive())
		{		
			return itGun->GetClipSize();
		}
		itGun++;

	}
	return 5;
}

//Gets damage of a paritcular gun
int cGunManager::GetDamage()
{
	itGun = liGuns.begin();
	while (itGun!=liGuns.end())
	{
		//itGun->Update(elapsedTimeS);
		if(itGun->GetActive())
		{		
			return itGun->GetDamage();
		}
		itGun++;

	}
	return 1;
}